﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DeliverCost.aspx.cs" Inherits="ZX.WebApp.Crm.Deliver.DeliverCost" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/Public.js" type="text/javascript"></script>
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <div>
    <div class="extendDiv">
            <h3><div style="width:700px;">大课费用列表
                                </div></h3>
            <div id="cellediting"></div>
        </div>
    </div>
    </form>
</body>
<script type="text/javascript">
    var myDataSource, myDataTable;
    var Id = "", flag = "",  const_Height = "", uId = "" ;
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () { });
    YAHOO.util.Event.addListener(window, "load", function () {
        Id =getPar1("id");
        flag = getPar1("flag");
        if (flag == "hwsh") {
            hBindData();
        } else if (flag == "cwsh") {
            cBindData();
        }
    });
    var cBindData = function () {
        YAHOO.example.InlineCellEditing = function () {
            var myColumnDefs = [
            { key: 'OcbdID', label: 'OcbdID', width: 110, sortable: true, resizeable: true },
            { key: 'RecID', label: '序号', width: 110, sortable: true, resizeable: true },
            { key: 'Project', label: '费用大类项目', width: 110, sortable: true, resizeable: true },
            { key: 'DetailsProject', label: '费用用明细项目', width: 110, sortable: true, resizeable: true },
            { key: 'ActualAmount', label: '实批预算金额', width: 110, sortable: true, resizeable: true },

            { key: 'ConferenceActualAmount', label: '会务实际金额', width: 80, sortable: true, resizeable: true
            },
            { key: 'FinancialActualAmount', label: '财务实际金额', width: 80, sortable: true, resizeable: true,
                editor: new YAHOO.widget.TextboxCellEditor({ validator: YAHOO.widget.DataTable.validateNumber })
            },
                { key: 'Remark', label: '备注', width: 110, sortable: true, resizeable: true }
            ];
            myDataSource = new YAHOO.util.DataSource([{ "OcbdID": "", "RecID": "", "Project": "",
                "DetailsProject": "", "ActualAmount": "", "ConferenceActualAmount": "", "FinancialActualAmount": "", "Remark": ""
            }]);
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
            myDataSource.responseSchema = {
                fields: ['OcbdID', 'RecID', 'Project', 'DetailsProject', 'ActualAmount', 'ConferenceActualAmount', 'FinancialActualAmount', 'Remark']
            };
            myDataTable = new YAHOO.widget.ScrollingDataTable("cellediting", myColumnDefs, myDataSource,
                        { width: "99.8%", height: const_Height, selectionMode: "single" });

            var onEventSaveCellEditor = function (oArgs) {
                SaveValue(oArgs.editor._oColumn.key, oArgs.newData, oArgs.oldData);
            }
            myDataTable.subscribe("rowMouseoverEvent", myDataTable.onEventHighlightRow);
            myDataTable.subscribe("rowMouseoutEvent", myDataTable.onEventUnhighlightRow);
            myDataTable.subscribe("rowClickEvent", myDataTable.onEventSelectRow);
            //myDataTable.subscribe("rowDblclickEvent", onRowDoubleSetColonel);
            myDataTable.subscribe("cellClickEvent", myDataTable.onEventShowCellEditor);
            myDataTable.subscribe("editorSaveEvent", onEventSaveCellEditor);
            myDataTable.subscribe("checkboxClickEvent", function (oArgs) {
                var elCheckbox = oArgs.target;
                var oRecord = this.getRecord(elCheckbox);
                oRecord.setData("iSun_Selected", elCheckbox.checked);
            });
            var onEventSaveCellEditor = function (oArgs) {
                SaveValue(oArgs.editor._oColumn.key, oArgs.newData, oArgs.oldData);
            }
            myDataTable.hideColumn(parseInt(0)); myDataTable.refreshView();
            LoadData();
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        } ();
    }
    var hBindData = function () {
        YAHOO.example.InlineCellEditing = function () {
            var myColumnDefs = [
            { key: 'OcbdID', label: 'OcbdID', width: 110, sortable: true, resizeable: true },
            { key: 'RecID', label: '序号', width: 110, sortable: true, resizeable: true },
            { key: 'Project', label: '费用大类项目', width: 110, sortable: true, resizeable: true },
            { key: 'DetailsProject', label: '费用用明细项目', width: 110, sortable: true, resizeable: true },
            { key: 'ActualAmount', label: '实批预算金额', width: 110, sortable: true, resizeable: true },
           
            {key: 'ConferenceActualAmount', label: '会务实际金额', width: 80, sortable: true, resizeable: true
            , editor: new YAHOO.widget.TextboxCellEditor({ validator: YAHOO.widget.DataTable.validateNumber })
            },
            {key: 'FinancialActualAmount', label: '财务实际金额', width: 80, sortable: true, resizeable: true
		    },
                { key: 'Remark', label: '备注', width: 110, sortable: true, resizeable: true }
            ];
		        myDataSource = new YAHOO.util.DataSource([{ "OcbdID": "", "RecID": "", "Project": "",
		            "DetailsProject": "", "ActualAmount": "", "ConferenceActualAmount": "", "FinancialActualAmount": "", "Remark": ""
		        }]);
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
            myDataSource.responseSchema = {
                fields: ['OcbdID', 'RecID', 'Project', 'DetailsProject', 'ActualAmount', 'ConferenceActualAmount', 'FinancialActualAmount', 'Remark']
            };
            myDataTable = new YAHOO.widget.ScrollingDataTable("cellediting", myColumnDefs, myDataSource,
                        { width: "99.8%", height: const_Height, selectionMode: "single" });

            var onEventSaveCellEditor = function (oArgs) {
                SaveValue(oArgs.editor._oColumn.key, oArgs.newData, oArgs.oldData);
            }
            myDataTable.subscribe("rowMouseoverEvent", myDataTable.onEventHighlightRow);
            myDataTable.subscribe("rowMouseoutEvent", myDataTable.onEventUnhighlightRow);
            myDataTable.subscribe("rowClickEvent", myDataTable.onEventSelectRow);
            //myDataTable.subscribe("rowDblclickEvent", onRowDoubleSetColonel);
            myDataTable.subscribe("cellClickEvent", myDataTable.onEventShowCellEditor);
            myDataTable.subscribe("editorSaveEvent", onEventSaveCellEditor);
            myDataTable.subscribe("checkboxClickEvent", function (oArgs) {
                var elCheckbox = oArgs.target;
                var oRecord = this.getRecord(elCheckbox);
                oRecord.setData("iSun_Selected", elCheckbox.checked);
            });
            myDataTable.hideColumn(parseInt(0)); myDataTable.refreshView();
            LoadData();
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        } ();
    }
    var SaveValue = function (f, newData, oldData) {
        var recordID = myDataTable.getSelectedRows()[0];
        if (recordID != null && recordID.length != 1) {
            record = myDataTable.getRecord(recordID);
            record._oData[f] = newData;
            var sId = record._oData["OcbdID"];
            var sFinancialActualAmount = record._oData["FinancialActualAmount"];
            var sConferenceActualAmount = record._oData["ConferenceActualAmount"];
            if (f == "FinancialActualAmount") {
                if (sFinancialActualAmount == "0") {
                    alert("数值不能0!");
                    record._oData[f] = oldData;
                    record._oData["FinancialActualAmount"] = oldData;
                } else {
                    CheckAccount(sId, sFinancialActualAmount, sConferenceActualAmount);
                }
            }
           else if (f == "ConferenceActualAmount") {
                if (sConferenceActualAmount == "0") {
                    alert("数值不能0!");
                    record._oData[f] = oldData;
                    record._oData["ConferenceActualAmount"] = oldData;
                } else {
                    CheckAccount(sId, sFinancialActualAmount, sConferenceActualAmount);
                }
            }
        }
    }
    var CheckAccount = function (sId, sFinancialActualAmount, sConferenceActualAmount) {
        var url = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&flag=" + flag + "&id=" + sId + " &ConferenceActualAmount=" + sConferenceActualAmount + "&FinancialActualAmount=" + sFinancialActualAmount + " &action=update&entity=bpm_OpenClassBudgetMaster";
        YAHOO.util.Connect.asyncRequest('GET', url,
            { success: function (res) {
                try {
                    var str = res.responseText;
                    if (str != "1") {
                        alert(str);
                    } else {
                        if (IsReresh == 1) {
                            QueryData();
                        }
                    }
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
            });
    }
    //选择客户编码显示客户信息
    var LoadData = function () {
        var vId = " txtProductLayoutID='" +decodeURI(Id) + "'  order by RecID";
        YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_bpm_OpenClassBudgetMaster&customCondition=" + encodeURI(vId) + "",
            { success: function (res) {
                try {
                    var str = res.responseText;
                    var arr = [];
                    var obj = eval(str);
                    SetFormValue(obj);
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
            });
    }
    //设置值
    var SetFormValue = function (obj) {
        var arr = eval(obj);
        myDataSource.liveData = arr;
        myDataTable.getDataSource().sendRequest(null, { success: myDataTable.onDataReturnInitializeTable }, myDataTable);
    }
</script>
</html>

